package com.cheyunkeji.er.view.evaluate;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.cheyun.netsalev3.R;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Michael on 2017/4/5 11:42.
 */

public class CarFrameworkCheckItemView extends RelativeLayout {

    @BindView(R.id.tv_index_number)
    TextView tvIndexNumber;
    @BindView(R.id.tv_item_desc)
    TextView tvItemDesc;
    @BindView(R.id.iv_arrow_right)
    ImageView ivArrowRight;
    @BindView(R.id.tv_condition)
    TextView tvCondition;
    @BindView(R.id.tv_content)
    LinearLayout tvContent;
    private View rootView;

//   是否为该项对应的车部位结构添加了故障色块，默认为false
    private boolean hasAddedFaultColor = false ;

    public CarFrameworkCheckItemView(Context context) {
        super(context);
        initView(context);
    }

    public CarFrameworkCheckItemView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView(context);

        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.CarFrameworkCheckItemView);

        for (int i = 0; i < typedArray.getIndexCount(); i++) {

            switch (typedArray.getIndex(i)) {
                case R.styleable.CarFrameworkCheckItemView_check_item_bkg_color:
                    tvContent.setBackgroundColor(typedArray.getColor(typedArray.getIndex(i), Color.parseColor("#00000000")));
                    break;
                case R.styleable.CarFrameworkCheckItemView_check_item_desc:
                    tvItemDesc.setText(typedArray.getString(typedArray.getIndex(i)));
                    break;
                case R.styleable.CarFrameworkCheckItemView_check_item_index:
                    tvIndexNumber.setText(typedArray.getString(typedArray.getIndex(i)));
                    break;

                default:
                    break;
            }
        }
        typedArray.recycle();
    }

    public CarFrameworkCheckItemView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context);

    }

    public void initView(Context context) {

        rootView = LayoutInflater.from(context).inflate(R.layout.er_car_archive_framework_check_item, this, true);
        ButterKnife.bind(this, rootView);

    }

//    展示错误状况信息
    public void showItemProblem(String problemDesc,boolean hasProblem){
        tvCondition.setText(problemDesc);
        if(hasProblem)
            tvCondition.setTextColor(Color.parseColor("#ff1300"));
        else
            tvCondition.setTextColor(Color.parseColor("#6f6f6f"));

    }

    public void sethasFaultColorAdded(boolean hasAddedFaultColor){
        this.hasAddedFaultColor = hasAddedFaultColor ;
    }

    public boolean hasFaultColorAdded(){
        return this.hasAddedFaultColor ;
    }

}
